﻿<%@ WebHandler Language="C#" Class="AssesmentPositionLoad" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using Assesment.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;
using Assesment.Library.Enum;
using Assesment.Web.Support;
using Newtonsoft.Json.Linq;
using Assesment.Library.DomainObject.Administration.Catalog;
using Assesment.Library.DataAccess.Transaction;
using Assesment.Library.DomainObject.Transaction;
using Training.Library.DataAccess.Administration.Catalog;
using Training.Library.DomainObject.Administration.Catalog;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;
using System.Text;

  public class AssesmentPositionLoad :  Assesment.Web.BaseHandler {

        AssesmentPositionRepo AssesmentPositionDal = new AssesmentPositionRepo(ConfigurationManager.ConnectionStrings["AssesmentConn"].ConnectionString);
        string MethodName = string.Empty;
        
        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);
            StringBuilder sbProject = new StringBuilder();
            string AssesmentPositionID = string.Empty;
            string AssesmentDate = string.Empty;
            string NamaKaryawan = string.Empty;
            string Jabatan = string.Empty;
            string LokasiKerja = string.Empty;
            string Departemen = string.Empty;
            string Lokasi = string.Empty;
            string JabatanTujuan = string.Empty;

            if (context.Request.Params["method"] != null)
                MethodName = context.Request.Params["method"];


            if (MethodName == "getbyAssesmentPositionID_NIK")
            {
                int PositionIDAssesment = Convert.ToInt32(context.Request.Params["PositionIDAssesment"].ToString());
                string NIK = context.Request.Params["NIK"].ToString();

                AssesmentPosition obj = AssesmentPositionDal.GetByPositionIDAssesment_NIK(PositionIDAssesment, NIK);
                if (obj != null)
                {
                    AssesmentPositionID = obj.AssesmentPositionID.ToString();
                    AssesmentDate = obj.AssesmentDate.Value.ToString("dd/MM/yyyy");
                }

                sbProject = new StringBuilder();
                sbProject.Append("{");
                sbProject.AppendFormat("  {0}AssesmentPositionID{0}:{0}{1}{0}", "\"", AssesmentPositionID);
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}AssesmentDate{0}:{0}{1}{0}", "\"", AssesmentDate);
                sbProject.Append("}");
                context.Response.Write(sbProject.ToString());
               
            }

            if (MethodName == "getbyidLoadData")
            {
                 AssesmentPositionID = context.Request.Params["AssesmentPositionID"].ToString();

                AssesmentPosition obj = AssesmentPositionDal.GetById(Convert.ToInt32(AssesmentPositionID));
                if (obj != null)
                {
                    //AssesmentPositionID = obj.AssesmentPositionID.ToString();
                    KaryawanRepo KaryawanDal = new KaryawanRepo(ConfigurationManager.ConnectionStrings["TrainingConn"].ConnectionString);
                    Karyawan objKaryawan = KaryawanDal.GetById(obj.NIK);
                    if (objKaryawan != null)
                    {
                        NamaKaryawan = objKaryawan.NamaKaryawan;

                        CabangRepo CabangDal = new CabangRepo(ConfigurationManager.ConnectionStrings["TrainingConn"].ConnectionString);
                        Cabang objCabang = CabangDal.GetById(Convert.ToInt32(objKaryawan.CabangID));
                        if (objCabang != null)
                            LokasiKerja = objCabang.NamaCabang;

                        PositionRepo PositionDal = new PositionRepo(ConfigurationManager.ConnectionStrings["JobDescConn"].ConnectionString);
                        Position objPosition = PositionDal.GetById(Convert.ToInt32(objKaryawan.PositionID));
                        if (objPosition != null)
                            Jabatan = objPosition.PositionName;

                        Position objJabatanTujuan = PositionDal.GetById(Convert.ToInt32(obj.PositionIDAssesment));
                        if (objJabatanTujuan != null)
                        {
                            JabatanTujuan = objJabatanTujuan.PositionName;
                            DepartmentRepo DepartmentDal = new DepartmentRepo(ConfigurationManager.ConnectionStrings["JobDescConn"].ConnectionString);
                            Department objDepartemen = DepartmentDal.GetById(Convert.ToInt32(objJabatanTujuan.DepartmentID));
                            if (objDepartemen != null)
                                Departemen = objDepartemen.DepartmentDesc;


                            LocationRepo LocationDal = new LocationRepo(ConfigurationManager.ConnectionStrings["JobDescConn"].ConnectionString);
                            Location objLocation = LocationDal.GetById(Convert.ToInt32(objJabatanTujuan.LocationID));
                            if (objLocation != null)
                                Lokasi = objLocation.Name;
                        }
                        
                        
                    }
                    
                    AssesmentDate = obj.AssesmentDate.Value.ToString("dd/MM/yyyy");
                }
                sbProject = new StringBuilder();
                sbProject.Append("{");
                sbProject.AppendFormat("  {0}NamaKaryawan{0}:{0}{1}{0}", "\"", NamaKaryawan);
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}Jabatan{0}:{0}{1}{0}", "\"", Jabatan);
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}LokasiKerja{0}:{0}{1}{0}", "\"", LokasiKerja);
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}AssesmentDate{0}:{0}{1}{0}", "\"", AssesmentDate);
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}Departemen{0}:{0}{1}{0}", "\"", Departemen);
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}JabatanTujuan{0}:{0}{1}{0}", "\"", JabatanTujuan);
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}Lokasi{0}:{0}{1}{0}", "\"", Lokasi);
                sbProject.Append(",");
                sbProject.AppendFormat("  {0}AssesmentPositionID{0}:{0}{1}{0}", "\"", AssesmentPositionID);
                sbProject.Append("}");
                context.Response.Write(sbProject.ToString());
            }

           
            
            }

       
        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

